#!/bin/bash

baseDirForScriptSelf=$(cd "$(dirname "$0")"; pwd)
PWDNOW=${baseDirForScriptSelf}

eval $(grep logPath ${PWDNOW}/taginfo1.cfg) #
eval $(grep HIVE_DATABASE ${PWDNOW}/taginfo1.cfg) #
eval $(grep TBNAME_TAG ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH ${PWDNOW}/taginfo1.cfg) #
eval $(grep TBNAME_TAG_ANALYSE ${PWDNOW}/taginfo1.cfg) #
eval $(grep QUEUE ${PWDNOW}/taginfo1.cfg) #
eval $(grep TBNAME_TAG_3G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TBNAME_TAG_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TAG_5C_3G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TAG_5C_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TAG_3C_3G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TAG_3C_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH_5C_3G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH_3C_3G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH_5C_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH_3C_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep HIVE_DATABASE_5C ${PWDNOW}/taginfo1.cfg) #
#set mapreduce.job.queuename=${QUEUE};
DAY=$1
PRO_3G=$2
PRO_4G=$3

citydatatypepath=C_DPI_${PRO_4G}_4G
echo $citydatatypepath
logTagInfoAnalyse=$logPath/Analyse/${DAY}
echo "日期：$DAY 省份：$PRO_3G $PRO_4G 数据库：${HIVE_DATABASE} 对列：${QUEUE}"

hive -e "
use ${HIVE_DATABASE};
set mapred.max.map.failures.percent=100;
set mapred.max.reduce.failures.percent=100;
set hive.exec.reducers.max=200;
set hive.exec.max.created.files=655350;
set mapred.max.split.size=268435456;
set mapred.min.split.size.per.node=134217728;
set mapred.min.split.size.per.rack=134217728;
set hive.hadoop.supports.splittable.combineinputformat=true;
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
set hive.merge.mapfiles=true;
set hive.merge.mapredfiles=true;
set hive.merge.size.per.task=268435456;
set hive.merge.smallfiles.avgsize=134217728;
set hive.auto.convert.join=false;
set hive.groupby.skewindata=true;
set hive.skewjoin.key=100000;
set hive.optimize.skewjoin=true;
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;


CREATE EXTERNAL TABLE IF NOT EXISTS ${HIVE_DATABASE}.${TBNAME_TAG_3G}(
imsi  string comment 'IMSI号',
mdn  string comment '手机号',
meid string comment 'MEID号',
bsid string comment '基站标识',
starttime  string comment '业务流开始时间',
endtime   string comment '业务流结束时间',
duration  string comment '持续时间',
download  string comment '下行流量',
upload    string comment '上行流量',
servicetype  string comment '服务类型',
url    string comment 'url地址',
host   string comment '域名',
dataType   string comment '数据类型',      
jinrong string comment '金融标签',                    
fangchan string comment '房产标签',        
quyufangchan string comment '区域房产标签',    
weixin string comment '微信标签',                
RESERVER1 string comment '保留1',
RESERVER2 string comment '保留2',
RESERVER3 string comment '保留3'
)
PARTITIONED BY(data_type string comment '数据来源类型 3G/4G',datetime string comment '日期',pro string comment 'DPI来源省',mm string comment '匹配')
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\|';




CREATE EXTERNAL TABLE IF NOT EXISTS ${HIVE_DATABASE}.${TBNAME_TAG_4G}(
imsi  string comment 'IMSI号',
mdn  string comment '手机号',
meid string comment 'MEID号',
bsid string comment '基站标识',
starttime  string comment '业务流开始时间',
endtime   string comment '业务流结束时间',
duration  string comment '持续时间',
download  string comment '下行流量',
upload    string comment '上行流量',
servicetype  string comment '服务类型',
url    string comment 'URL地址',
host	string comment '域名',
dataType   string comment '数据类型',      
jinrong string comment '金融标签',          
fangchan string comment '房产标签',       
quyufangchan string comment '区域房产标签',              
weixin string comment '微信标签',      
RESERVER1 string comment '保留1',
RESERVER2 string comment '保留2',
RESERVER3 string comment '保留3'
)
PARTITIONED BY(city_data_type string comment '数据来源类型 3G/4G',datetime string comment '日期')
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\|';


alter table ${HIVE_DATABASE}.${TBNAME_TAG_4G} drop if exists PARTITION (city_data_type='${citydatatypepath}',datetime ='${DAY}');
alter table ${HIVE_DATABASE}.${TBNAME_TAG_4G} add if not exists partition (city_data_type='${citydatatypepath}',datetime ='${DAY}') location '${TABLE_PATH_3C_4G}/${citydatatypepath}/${DAY}';



">>${logTagInfoAnalyse}/${PRO_4G}.log 2>&1

